﻿using MediatR;
using Microsoft.IdentityModel.Tokens;
using Production_Get.API.Application.Commands.OrderShow;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.warehouses;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Warehousingtes
{
    //仓库
    public class WarehouseSrcetenHandler : IRequestHandler<WarehouseSrcetenCommend, Result>
    {
        private readonly IBaseRepositoryGet<Warehouse> Warehouse;

        public WarehouseSrcetenHandler(IBaseRepositoryGet<Warehouse> Warehouse)
        {
            this.Warehouse = Warehouse;
        }

        public async Task<Result> Handle(WarehouseSrcetenCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM Warehouse";
            var list = Warehouse.GetAll(sql, default).ToList();

            if (request.WarehouseId>0)
            {
                list = list.Where(x => x.WarehouseId==request.WarehouseId).ToList();
            }

            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }

            return result;
        }
    }
}
